package com.digitalchina.lxnsy.viewholder;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.AttentionTrainVO;
import com.digitalchina.lxnsy.entity.TrainVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import java.util.List;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：关注页培训列表
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：jiabo
 * 创建时间：2017/3/24 14:30
 * 修改备注：
 * ================================================
 */
public class AttentionTrainingHolder extends BaseViewHolder<AttentionTrainVO> {

    private SimpleDraweeView ivHead; // 头像
    private TextView tvName; // 名字
    private TextView tvTime; // 时间
    private TextView tvTitle; // 标题
    private TextView tvLocation; // 位置

    public AttentionTrainingHolder(View itemView) {
        super(itemView);
    }

    public AttentionTrainingHolder(ViewGroup parent) {
        super(parent, R.layout.item_attention_training);

        tvTitle = $(R.id.item_attention_train_tv_title);
        tvName = $(R.id.item_attention_train_tv_name);
        tvTime = $(R.id.item_attention_train_tv_time);
        tvLocation = $(R.id.item_attention_train_tv_location);
        ivHead = $(R.id.item_attention_train_iv_head);
    }

    @Override
    public void setData(AttentionTrainVO data) {
        super.setData(data);

        TrainVO trainVO = data.getTrain();
        if (trainVO == null) {
            return;
        }
        List<TrainVO.TrainingTimesBean> trainingTimes = trainVO.getTrainingTimes();
        if (trainingTimes != null) {
            String times = "";
            for (int i = 0; i < trainingTimes.size(); i++) {
                TrainVO.TrainingTimesBean trainingTimesBean = trainingTimes.get(i);
                times += trainingTimesBean.getTrainDate() + "  " + trainingTimesBean.getStartTime() +
                        "—" + trainingTimesBean.getEndTime();
                if (i != trainingTimes.size() - 1) {
                    times += "\n";
                }
            }
            tvTime.setText(times);
        }

        TrainVO.AgriTeacherBean agriTeacher = trainVO.getAgriTeacher();
        if (agriTeacher != null) {
            tvName.setText(agriTeacher.getName());
            FrescoUtil.showImageSmall(agriTeacher.getImg(), ivHead);
        }

        tvTitle.setText(trainVO.getTitle());

        SpannableString location = new SpannableString("培训地址：" + trainVO.getFullAddress());
        location.setSpan(new ForegroundColorSpan(0xff898989), 5, location.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        location.setSpan(new AbsoluteSizeSpan(12, true), 5, location.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvLocation.setText(location);
    }
}